﻿using System;
using System.Collections.Generic;

namespace Flagwind.Data.Entity
{
	/// <summary>
	/// 字段大小辅助类。
	/// </summary>
	internal static class FieldSizeUtility
	{
		#region 私有字段

		private readonly static Dictionary<string, int> _dictionary = new Dictionary<string, int>();

		#endregion

		#region 公共方法

		/// <summary>
		/// 设置指定字段的大小。
		/// </summary>
		/// <param name="ownerName">所有者名称。</param>
		/// <param name="fieldName">字段名称。</param>
		/// <returns>字段大小。</returns>
		public static int GetFieldSize(string ownerName, string fieldName)
		{
			if(string.IsNullOrWhiteSpace(ownerName))
			{
				throw new ArgumentNullException("ownerName");
			}
			if(string.IsNullOrWhiteSpace(fieldName))
			{
				throw new ArgumentNullException("fieldName");
			}
			var key = string.Format("{0}_{1}", ownerName, fieldName);
			if(_dictionary.ContainsKey(key))
			{
				return _dictionary[key];
			}
			return -1;
		}

		/// <summary>
		/// 获取指定字段的大小。
		/// </summary>
		/// <param name="ownerName">所有者名称。</param>
		/// <param name="fieldName">字段名称。</param>
		/// <param name="fieldSize">字段大小。</param>
		public static void SetFieldSize(string ownerName, string fieldName, int fieldSize)
		{
			if(string.IsNullOrWhiteSpace(ownerName))
			{
				throw new ArgumentNullException("ownerName");
			}
			if(string.IsNullOrWhiteSpace(fieldName))
			{
				throw new ArgumentNullException("fieldName");
			}
			var key = string.Format("{0}_{1}", ownerName, fieldName);
			_dictionary[key] = fieldSize;
		}

		#endregion
	}
}